<?php
    require_once 'classes/JobPost.php';
	require_once 'classes/Employer.php';
    require_once 'classes/Login.php';
    $Login = new Login();
	$Employer = new Employer();
    $JobPost = new JobPost();
	$empID = 0;
    include 'includes/header.inc.php';
    $jobID = $_GET['jobID'];
	if($Login->verify()){
    	$empID = $_SESSION['employerID'];
	}
    $jobListing = $JobPost->getPost($jobID,$empID);
	$employerDetails = $Employer->getSpecificEmployerDetails($jobListing[0]);
    if($jobListing != 'ERROR')
    {
        $expiredDate = strtotime("-90 days");
        $jobDate = strtotime($jobListing[8]);
        if($jobDate < $expiredDate)
        {
            $expiredFlag = true;
        }
        else
        {
            $expiredFlag = false;
        }
        $jobLocations = $JobPost->getLocations($jobID);
        $companyName = $Login->getCompanyName($jobListing[0]);

/* Form Validation Script */ ?>
<script language="JavaScript">
function validateForm(thisForm) {
		with (thisForm) {
			first_name.style.background = "#FFFFFF";
			last_name.style.background = "#FFFFFF";
			from_email.style.background = "#FFFFFF";
			confirm_email.style.background = "#FFFFFF";
			letter.style.background = "#FFFFFF";
			if (!first_name.value.length){
				alert("The First Name field is a required field.");
				first_name.style.background = "#FFF333";
				first_name.focus();
				return false;		
			}
			if (!last_name.value.length){
				alert("The Last Name field is a required field.");
				last_name.style.background = "#FFF333";
				last_name.focus();
				return false;		
			}
			if (!from_email.value.length) {
				alert("You must enter an email address.");
				from_email.style.background = "#FFF333";
				from_email.focus();
				return false;		
			}
			if (!confirm_email.value.length) {
				alert("You must enter your email address again.");
				confirm_email.style.background = "#FFF333";
				confirm_email.focus();
				return false;		
			}
			if (confirm_email.value != from_email.value) {
				alert("Your email entries to not match.");
				confirm_email.style.background = "#FFF333";
				from_email.style.background = "#FFF333";
				from_email.focus();
				return false;		
			}
			if (!letter.value.length) {
				alert("You must enter a note to the employer.");
				letter.style.background = "#FFF333";
				letter.focus();
				return false;		
			}
		}
		return true;
}
</script>

        <div id="postBox">
        <section id="advancedSearch">
            <h2>Advanced Search</h2>
            <form id="advSearch" action="#">
                <div id="leftAdvS" class="advS">
                    <label for="what">what</label>
                    <input id="what" type="text" />
                    <small>Job title, keywords, or company name</small>
                </div>
                <div id="centerAdvS" class="advS">
                    <label for="where">where</label>
                    <input id="where" type="text" />
                    <small>City, State, or Zip (Optional)</small>
                </div>
                <div id="rightAdvS" class="advS">
                    <input type="submit" name="advSearch" id="advSearch" class="button" value="Find Jobs" />
                </div>
            </form>
        </section>
        <hr />
        <section id="jobPost">
            <?php if($expiredFlag == true){ echo '<h1 class="expired">EXPIRED</h1>'; } ?>
            <h2><strong><?php echo $jobListing[1]; ?></strong></h2>
            <?php
                    if($jobListing[6] != 0){ echo '<p><strong>Company Name:</strong> '.$companyName.'</p>'; }
                    if($jobListing[7] != 0){ echo '<p class="jobLocation"><strong>Salary: </strong>'.$jobListing[4].'</p>'; }
                    foreach($jobLocations as $i=>$jobLocation)
                    {
                        $stateName = $JobPost->getStateName($jobLocation[2]);
                        echo '<p class="jobLocation">'.$jobLocation[1].', '.$stateName.'</p>';
                    }
                    $postDate = strtotime($jobListing[8]);
                    echo '<p>Date Posted: '.date("m/d/y", $postDate).'</p>';
             ?>
            <p>&nbsp;</p>
            <p><?php echo nl2br($jobListing[3]); ?></p>
            <p>&nbsp;</p>
                    <div id="loading"><img src="/sandbox1/media/images/loader.gif" alt="Loading..." /></div>
                    <div id="feedback"></div>
            <?php if(!$expiredFlag)
            { ?>
            <div align="right">
            <a href="viewJobPostAttach.php?jobID=<?php echo $jobID; ?>"><font color="#990000">
            <img src="media/images/attach.png" title="Apply with resume attached"  />Use Form To Attach Resume</font></a>
            <img src="media/images/spacer.png" />
            <a href="index.php" target="_blank" title="Click here to view terms and conditions."><font color="#000099">
            <strong>Terms and Conditions</strong></font></a>
            </div>
            <div id="form" class="applyForm">
                <fieldset>
                    <legend>Apply Here!</legend>
                        <form enctype="multipart/form-data" name="basic" method="post" action="process.php" onsubmit="return validateForm(this)">
                        <input type="hidden" name="action" value="ApplicationSendBasic" />
                        <?php /*<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />*/ ?>
                        <input type="hidden" name="to_name" value="<?php echo $employerDetails[0]['contactName']; ?>" />
                        <input type="hidden" name="to_email" value="<?php echo $employerDetails[0]['email']; ?>" />
                        <?php echo "<input type='hidden' name='subject' value='".$jobListing[3]."'/>"; ?>

						<p>
                            <label for="fName">First Name: </label>
                            <input name="first_name" id="fName" size="50" value="" />
                        </p>
                         <p>
                            <label for="lName">Last Name: </label>
                            <input name="last_name" id="lName" size="50" value="" />
                        </p>
                        <p> 
                            <label for="email">Your Email Address: </label>
                            <input name="from_email" id="email" size="50" value="" />
                        </p>
                        <p>
                            <label for="confEmail">Confirm Email Address:</label>
                            <input name="confirm_email" id="confEmail" size="50" value="" />
                        </p>
                        <p>
                            <label for="resumeText">Copy/Paste Resume:</label>
                            <textarea name="letter" id="resumeText" ></textarea>
                        </p>
                </fieldset><input type="submit" name="resume" id="resume" value="Agree with Terms" /><input type="button" name="resume" id="resume" value="Don't Agree" onclick="history.go(0)" />
 <?php } ?> 
        </section>
    </div>
<?php
    }
    else
    {
        echo '<div id="noResults">The job post you selected, is either deleted or expired.</div>';
    }
include 'includes/footer.inc.php'; ?>